home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / comms / netsoftware / archie38_1.lha / archie-1.4 / ptalloc.c < prev    next >
C/C++ Source or Header  |  1995-01-05  |  2KB  |  95 lines

  1. /*
  2.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  3.  *
  4.  * For copying and distribution information, please see the file
  5.  * <copyright.h>.
  6.  */
  7. /* Amiga port by Tomas Willis (tomas@cae.wisc.edu) January 1995 */
  8.  
  9. #include <stdio.h>
  10.  
  11. #include "pfs.h"
  12. #include "pmachine.h" /* for correct definition of ZERO */
  13. #ifdef MSDOS
  14. # define free _pfree   /* otherwise we get conflicts with free() */
  15. #endif
  16. #ifdef AMIGA
  17. # define free _pfree   /* otherwise we get conflicts with free() */
  18. #endif
  19.  
  20. static PTEXT    free = NULL;
  21. int         ptext_count = 0;
  22. int        ptext_max = 0;
  23.  
  24. //protos
  25. PTEXT ptalloc(void);
  26. void ptfree(PTEXT vt);
  27. void ptlfree(PTEXT vt);
  28.  
  29. /*
  30.  * ptalloc - allocate and initialize ptext structure
  31.  *
  32.  *    PTALLOC returns a pointer to an initialized structure of type
  33.  *    PTEXT.  If it is unable to allocate such a structure, it
  34.  *    returns NULL.
  35.  */
  36. PTEXT
  37. ptalloc(void)
  38.     {
  39.     PTEXT    vt;
  40.     if(free) {
  41.         vt = free;
  42.         free = free->next;
  43.     }
  44.     else {
  45.         vt = (PTEXT) malloc(sizeof(PTEXT_ST));
  46.         if (!vt) return(NULL);
  47.         ptext_max++;
  48.     }
  49.     ptext_count++;
  50.  
  51.     /* nearly all parts are 0 [or NULL] */
  52.     ZERO(vt);
  53.     /* The offset is to leave room for additional headers */
  54.     vt->start = vt->dat + MAX_PTXT_HDR;
  55.  
  56.     return(vt);
  57.     }
  58.  
  59. /*
  60.  * ptfree - free a VTEXT structure
  61.  *
  62.  *    VTFREE takes a pointer to a VTEXT structure and adds it to
  63.  *    the free list for later reuse.
  64.  */
  65. void
  66. ptfree(PTEXT vt)
  67. //    PTEXT    vt;
  68.     {
  69.     vt->next = free;
  70.     vt->previous = NULL;
  71.     free = vt;
  72.     ptext_count--;
  73.     }
  74.  
  75. /*
  76.  * ptlfree - free a VTEXT structure
  77.  *
  78.  *    VTLFREE takes a pointer to a VTEXT structure frees it and any linked
  79.  *    VTEXT structures.  It is used to free an entrie list of VTEXT
  80.  *    structures.
  81.  */
  82. void
  83. ptlfree(PTEXT vt)
  84. //    PTEXT    vt;
  85.     {
  86.     PTEXT    nxt;
  87.  
  88.     while(vt != NULL) {
  89.         nxt = vt->next;
  90.         ptfree(vt);
  91.         vt = nxt;
  92.     }
  93.     }
  94.  
  95.